<?php

class Testimonial_Widget_TestimonialController extends Engine_Content_Widget_Abstract
{
  
  public function indexAction()
  {
      
   $viewer = Engine_Api::_()->user()->getViewer();
    if( !Engine_Api::_()->core()->hasSubject() ) {
      return $this->setNoRender();
    }

    // Get subject and check auth
    $subject = Engine_Api::_()->core()->getSubject();
    if( !$subject->authorization()->isAllowed($viewer, 'view') ) {
        return $this->setNoRender();
    }
     $this->view->subject_id =  $subject->getIdentity();
    /*$viewer = Engine_Api::_()->user()->getViewer();
    
    // Get subject and check auth
    $subject = Engine_Api::_()->core()->getSubject('page');
    */
/*$element = $this->getElement();
    $element->setTitle($subject->getTitle());*/

    $table = Engine_Api::_()->getDbtable('testimonials','testimonial');
    $select = $table->select()->where('resource_id = ?',$subject->getIdentity())->where('approved = 1');
    $this->view->testimonials = $testimonials = $table->fetchAll($select);
 /*echo '<pre>';
 print_r($testimonials);*/
 
 if(count($testimonials) <= 0){
return $this->setNoRender();
      
 /*
      //echo "ia ma here ";exit;
  //   if( !$this->_helper->requireAuth()->setAuthParams('event', null, 'edit')->isValid() ) return;
    $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
    if( !Engine_Api::_()->core()->hasSubject() ) {
      return $this->setNoRender();
    }
    
    // Get subject and check auth
    $this->view->subject = $subject = Engine_Api::_()->core()->getSubject('event');
    //to check if not tournment then render widgets
    $event_type=$subject->event_type; 
     if($event_type=='Tournament') {             
    
    
    if( !$subject->authorization()->isAllowed($viewer, 'view') ) {
      return $this->setNoRender();
    } 
     $this->view->event = $subject; 
   
    //  echo "event id ".$this->getIdentity(); 
   
       $table = Engine_Api::_()->getDbTable('testimonials','testimonial');
  //  $select = $table->select()->where('event_id = ?',$subject->getIdentity())->where('link_type = ?','Coupon');
       $select = $table->select()
               ->where('event_id = ?',$subject->getIdentity())
               ->limit(devil);
      $photologo = $table->fetchAll($select);
      $this->view->edetail=$photologo; 
      
      }
    else {
           return $this->setNoRender(); 
      }
  */
  }
} 

}
